package com.jushu.storbox.constant;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import android.content.Context;
import android.util.Log;

import com.jushu.storbox.util.LogUtil;

public class ConfigurableConstants {

	private static Properties p = new Properties();

	/**
	 * @param propertyFileName
	 */
	public static void init(Context context) {
		Log.i("ConfigurableConstants", "start");
		InputStream in = null;
		try {
			in = context.getAssets().open("system.properties");
			if (in != null) {
				Log.i("ConfigurableConstants", "notnull");
				p.load(in);
				ClientConfig.SERVICEADD = p.getProperty("onebox_server_URL","");

				Log.i("ConfigurableConstants", ClientConfig.SERVICEADD);
			} else {
				Log.i("ConfigurableConstants", "null");
			}
		} catch (IOException e) {
			LogUtil.e("load system.properties into Constants error!");
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					LogUtil.e("close system.properties error!");
				}
			}
		}
	}

	/**
	 * @param key
	 * @param defaultValue
	 * @return String
	 */
	public static String getProperty(String key, String defaultValue) {
		if (p != null) {
			Log.i("ConfigurableConstants", "p>>>>notnull>>>" + key + ">>>"
					+ defaultValue);
		}
		return p.getProperty(key, defaultValue);
	}
}
